package cn.edu.shiep.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.context.annotation.Scope;

import com.opensymphony.xwork2.ActionSupport;
@ParentPackage("struts-default")
@Namespace("/")
@Scope(value="prototype")
public class BaseAction extends ActionSupport {

	private static final long serialVersionUID = 1696114915075818187L;
	protected HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	protected HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}

	protected ServletContext getServletContext() {
		return ServletActionContext.getServletContext();
	}

	protected HttpSession getHttpSession() {
		return getRequest().getSession();
	}

	protected void forward(String url) throws ServletException, IOException {
		RequestDispatcher dispatcher = getRequest().getRequestDispatcher(url);
		dispatcher.forward(getRequest(), getResponse());
	}
	
	protected Object getSessionObject(String sessionName) {
		HttpSession session = getHttpSession();
		return session.getAttribute(sessionName);
	}
}
